#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# @Time: 2019/7/19  17:32
# @Author: 余浪人
# @email: yulangren520@gmail.com

from apps.models import db, BaseModel
from apps.lib.public import random_click


class TL_Column_model(BaseModel):
    column_name = db.Column(db.String(64), comment='分类名称')
    column_link = db.Column(db.String(1024), comment='跳转链接')
    column_keyword = db.Column(db.String(1024), comment='分类关键词')
    column_description = db.Column(db.String(1024), comment='分类描述')
    column_order = db.Column(db.Integer, default=0, comment='分类排序')
    column_parent_id = db.Column(db.Integer, default=0, comment='父级ID|0_顶级')

    def __repr__(self):
        return f'分类:<{self.column_name}>'

    def keys(self):
        return 'column_name', 'column_link', 'column_keyword', 'column_description', 'column_parent_id', 'column_order'


class TL_Content_Model(BaseModel):
    title = db.Column(db.String(255), comment='标题')
    title_color = db.Column(db.String(10), comment='标题颜色')
    superior = db.Column(db.Integer, db.ForeignKey(TL_Column_model.id), comment='所属栏目')
    content = db.Column(db.Text, comment='内容')
    pay_content = db.Column(db.Text, comment='付费内容')
    permissions = db.Column(db.Integer, default=0, comment='可见性')
    reward = db.Column(db.FLOAT, comment='打赏金额')
    download = db.Column(db.Text, comment='下载地址')
    thumb_img = db.Column(db.Text, comment='缩略图片')
    clicks = db.Column(db.Integer, default=random_click, comment='点击数')
    author = db.Column(db.String(64), default='佚名', comment='作者')
    keyword = db.Column(db.String(512), comment='关键词')
    description = db.Column(db.String(512), comment='描述')
    contributor = db.Column(db.String(64), comment='投稿者')
    is_focus = db.Column(db.Boolean, default=0, comment='是否焦点图 | 0 否(默认) | 1 是')
    is_roll = db.Column(db.Boolean, default=0, comment='是否滚动图 | 0 否(默认) | 1 是')
    is_roll_text = db.Column(db.Boolean, default=0, comment='是否滚动文字 | 0 否(默认) | 1 是')
    is_index_stick = db.Column(db.Boolean, default=0, comment='是否首页置顶 | 0 否(默认) | 1 是')
    is_list_stick = db.Column(db.Boolean, default=0, comment='是否列表页置顶 | 0 否(默认) | 1 是')
    is_recommend = db.Column(db.Boolean, default=0, comment='是否推荐 | 0 否(默认) | 1 是')
    pro = db.relationship('TL_Column_model', backref='content_model')

    def __repr__(self):
        return f'内容标题: <{self.title}>'

    def keys(self):
        return 'title', 'title_color', 'superior', 'content', 'pay_content', 'permissions', 'reward', 'download', 'thumb_img', 'clicks', 'author', 'keyword', 'description', 'contributor', 'is_focus', 'is_roll', 'is_roll_text', 'is_index_stick', 'is_list_stick', 'is_recommend', 'update_time', 'uuid'


class TL_Comment_Model(BaseModel):
    content_uuid = db.Column(db.String(16), db.ForeignKey(TL_Content_Model.uuid), comment='内容id')
    comment_txt = db.Column(db.Text, comment='评论内容')
    user_qq = db.Column(db.String(12), comment='用户QQ')
    user_name = db.Column(db.String(32), comment='用户昵称')
    pro = db.relationship('TL_Content_Model', backref='comment_model')

    def __repr__(self):
        return f'评论用户: <{self.user_name}>'

    def keys(self):
        return 'content_uuid', 'comment_txt', 'user_qq', 'user_name', 'update_time', 'status'


class TL_Tags_Model(BaseModel):
    tag_name = db.Column(db.String(255), unique=True, comment='标签名')
    tag_click = db.Column(db.Integer, default=0, comment='访问数')

    def __repr__(self):
        return f'标签名: <{self.tag_name}>'

    def keys(self):
        return 'tag_name', 'tag_click'
